package 数独简单版;

import java.util.Scanner;

public class Main {
    static int N = 10;
    static boolean[][] row = new boolean[N][N];
    static boolean[][] col = new boolean[N][N];
    static boolean[][][] cell = new boolean[3][3][N];
    static char[][] g = new char[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        for (int i = 0; i < 9; i++) {
            String s = in.next();
            for (int j = 0; j < 9; j++) {
                g[i][j] = s.charAt(j);
                if (g[i][j] != '.') {
                    int t = g[i][j] - '0';
                    row[i][t] = col[j][t] = cell[i / 3][j / 3][t] = true;
                }
            }
        }
        dfs(0, 0);
    }

    private static boolean dfs(int x, int y) {
        if (y == 9) {
            return dfs(x + 1, 0);
        }
        if (x == 9) {
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    System.out.print(g[i][j]);
                }
                System.out.println();
            }
            return true;
        }
        if (g[x][y] != '.') {
            return dfs(x , y+1);
        }
        for (int i = 1; i <= 9; i++) {
            if (!row[x][i] && !col[y][i] && !cell[x / 3][y / 3][i]) {
                row[x][i] = col[y][i] = cell[x / 3][y / 3][i] = true;
                g[x][y] = (char) (i + '0');
                if (dfs(x, y + 1)) {
                    return true;
                }
                row[x][i] = col[y][i] = cell[x / 3][y / 3][i] = false;
                g[x][y] = '.';
            }
        }
        return false;
    }
}
